import axios from "axios";
import router from "@/router/index.js";
// 创建axios实例
const request=axios.create({
    baseURL:"http://localhost:8089",
    timeout:5000
})
// 添加请求拦截
request.interceptors.request.use(function(config){
    //添加token
    config.headers.Authorization = localStorage.getItem("token");
    return config;
})

// 添加请求响应
request.interceptors.response.use(function(response){
    // console.log(response,"-------response.data");
    if(response.data.code==401){
        localStorage.removeItem("token");
        router.push("/");
    }
    return response;
})
// 创建用户axios实例
const requestUserAPI=axios.create({
    baseURL:"http://localhost:9020",
    timeout:5000
})

// 创建站点axios实例
const requestStationAPI=axios.create({
    baseURL:"http://localhost:9040",
    timeout:5000
})
// 添加请求拦截
requestStationAPI.interceptors.request.use(function(config){
    //添加token
    config.headers.Authorization = +localStorage.getItem("token");
    return config;
})

// market
const requestMarketAPI=axios.create({
    baseURL:"http://localhost:9031",
    timeout:5000
})
// market 添加请求拦截
requestMarketAPI.interceptors.request.use(function(config){
    //添加token
    config.headers.Authorization = +localStorage.getItem("token");
    return config;
})

export { requestStationAPI };
export { requestUserAPI };
export {requestMarketAPI };
export default request;